package com.example.jpa.repository;

import com.example.jpa.Discuss;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.*;

import javax.transaction.Transactional;
import java.util.List;


public interface DiscussRepository extends JpaRepository<Discuss,Integer> {
  //1
  public List<Discuss> findByAuthorNotNull();
  //2
  @Query("SELECT c FROM t_comment c WHERE c.aId=?1")
    public List<Discuss> getDiscussPaged(Integer aid, Pageable pageable);
  //3
  @Query(value = "SELECT * FROM t_comment  WHERE  a_Id = ?1",nativeQuery = true)
  public List<Discuss> getDiscussPaged2(Integer aid,Pageable pageable);
  //4
  @Transactional
  @Modifying
  @Query("UPDATE t_comment c SET c.author = ?1 WHERE  c.id = ?2")
  public int updateDiscuss(String author,Integer id);
  //5
  @Transactional
  @Modifying
  @Query("DELETE  FROM t_comment c WHERE  c.id = ?1")
  public int deleteDiscuss(Integer id);

}
